export function createRouterMap(routers, routerOptions = {}) {
    let pathMap = routerOptions
    routers.forEach(router => {
        addRouterRecode(router, pathMap)

    });
    return pathMap
}

function addRouterRecode(router, pathMap, parent) {
    let path = parent ? `${parent.rootpath}/${router.path}` : router.path
    let recode = {
        rootpath: path,
        path: router.path,
        name: router.name,
        component: router.component,
        parent
    }
    if (!pathMap[path]) {
        pathMap[path] = recode
    }
    if (router.children) {
        router.children.forEach(router => {
            addRouterRecode(router, pathMap, recode)
        });
    }
    return pathMap
}
export function createRoute(recode, { path }) {
    //定义结构
    let metched = []
    if (recode) {
        //遍历
        while (recode) {
            metched.unshift(recode) //  1：/about/a  /about
            recode = recode.parent //一层一层找
        }
    }

    return {
        path,
        metched
    }
}